//package org.zbclan.bf2.rcon.common.server;
//
//import java.io.File;
//import java.io.IOException;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.xml.transform.Transformer;
//import javax.xml.transform.TransformerConfigurationException;
//import javax.xml.transform.TransformerException;
//import javax.xml.transform.TransformerFactory;
//import javax.xml.transform.TransformerFactoryConfigurationError;
//import javax.xml.transform.stream.StreamResult;
//import javax.xml.transform.stream.StreamSource;
//
//import com.google.inject.Singleton;
//
//@Singleton
//public class LevelInfoServlet extends HttpServlet {
//
//	/**
//	 * 
//	 */
//	private static final long serialVersionUID = -2518142993216474420L;
//
//	@Override
//	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
//			throws ServletException, IOException {
//
//		String name = req.getParameter("name");
//		// File levelDir = new File(System.getProperty(Options.BF2_LEVELS_DIR),
//		// name);
//		File levelDir = new File(Options.BF2_LEVELS_DIR, name);
//		File infoDir = new File(levelDir, "info");
//
//		File xmlFile = new File(infoDir, name + ".desc");
//		// echoXml(resp, xslFile);
//		try {
//			File xslFile = new File(getServletContext()
//					.getRealPath("/info.xsl"));
//			echoJson(resp, name, xmlFile, xslFile);
//		} catch (Exception e) {
//			throw new ServletException(e);
//		}
//
//		return;
//	}
//
//	private void echoJson(HttpServletResponse resp, String name, File xmlFile,
//			File xslFile) throws TransformerFactoryConfigurationError,
//			TransformerConfigurationException, TransformerException,
//			IOException {
//
//		resp.setContentType("text/javascript");
//
//		TransformerFactory tFactory = TransformerFactory.newInstance();
//		Transformer transformer = tFactory.newTransformer(new StreamSource(
//				xslFile));
//		transformer.setParameter("id", name);
//		transformer.transform(new StreamSource(xmlFile),
//				new StreamResult(resp.getWriter()));
//
//		return;
//	}
//
//	// /**
//	// * @deprecated
//	// * @param resp
//	// * @param xmlFile
//	// * @throws IOException
//	// * @throws FileNotFoundException
//	// */
//	// private void echoXml(HttpServletResponse resp, File xmlFile)
//	// throws IOException, FileNotFoundException {
//	// resp.setContentType("text/xml");
//	// ServletOutputStream w = resp.getOutputStream();
//	// w.println("<?xml version='1.0' encoding='UTF-8'?>");
//	// w.println("<?xml-stylesheet href='info.xsl' type='text/xsl' ?>");
//	// IOUtils.copy(new FileInputStream(xmlFile), w);
//	// }
//
//}
